package ichain

import (
	reqContext "context"

	"git.cloud.inspur.com/ichain/ichain-protos-go/common"
	iamCfg "git.cloud.inspur.com/ichain/ichain-protos-go/iam"
)

const (
	ChainGroupKey       ConfigGroupKey = ""
	ConsenserGroupKey   ConfigGroupKey = "Consenser"
	ApplicationGroupKey ConfigGroupKey = "Application"
)

const (
	V1_0Capability = "V1_0" // 目前ichain为1.0版本
)

// OrgAnchorInode 锚节点
type OrgAnchorInode struct {
	Org  string
	Host string
	Port int32
}

// ChainConfigService 链配置服务
type ChainConfigService interface {

	// Query 请求链配置
	Query(reqCtx reqContext.Context) (ChainCfg, error)

	// QueryBlock 请求配置区块
	QueryBlock(reqCtx reqContext.Context) (*common.Block, error)
}

type ConfigGroupKey string

// ChainCfg 链配置的抽象接口
type ChainCfg interface {
	ID() string
	BlockNumber() uint64
	IAMs() []*iamCfg.IAMConfig
	AnchorInodes() []*OrgAnchorInode
	Consensers() []string
	Versions() *Versions
	// HasCapability 校验链是否具备某些功能
	HasCapability(group ConfigGroupKey, capability string) bool
}

// ChainMembership 校验链成员
type ChainMembership interface {
	Validate(serializedID []byte) error
	// Verify 验证签名
	Verify(serializedID []byte, msg []byte, sig []byte) error
	// ContainsIAM 是否包含某一IAM
	ContainsIAM(iam string) bool
}

type Versions struct {
	ReadSet  *common.ConfigGroup
	WriteSet *common.ConfigGroup
	Chain    *common.ConfigGroup
}

// BlockchainInfoResponse 包一层BlockChainInfo
type BlockchainInfoResponse struct {
	BCI      *common.BlockChainInfo
	Endorser string
	Status   int32
}
